package com.openscorer;

import java.util.ArrayList;
import java.util.Iterator;

public class Structure extends Scorable {
	public Structure(String name, FormattingOptions foptions) {
		name_ = name;
		foptions_ = foptions;
		list_ = new ArrayList<Scorable>();
	}
	public Scorable get(String name) {
		for (int i = 0; i < list_.size(); ++i) {
			if (list_.get(i).getName().equals(name)) {
				return list_.get(i);
			}
		}
		throw new ScorableTypeException();
	}
	public void add(Scorable s) {
		list_.add(s);
	}
	
	// The following are for internal use only.
	public FormattingOptions getFOptions() { return foptions_; }
	public String getName() { return name_; }
	public void visit(ScorableVisitor v) {
		v.visitStructure(this);
		for (Iterator<Scorable> it = list_.iterator(); it.hasNext();) {
			v.visit(it.next());
		}
		v.endStructure(this);
	}
	public Structure deepCopy() {
		Structure returnable = new Structure(name_, foptions_);
		for (Iterator<Scorable> it = list_.iterator(); it.hasNext();) {
			returnable.list_.add(it.next().deepCopy());
		}
		return returnable;
	}
	String name_;
	FormattingOptions foptions_;
	ArrayList<Scorable> list_;
}
